from pyactivemq import ActiveMQConnectionFactory
from pyactivemq import AcknowledgeMode
from pyactivemq import DeliveryMode


def createMessage(index, messageLength=8192):
    string = 'Message[%d]:' % index
i = len(string)
while (i < messageLength):
    string += ' '
i += 1
return string

url = 'failover:(tcp://localhost:61616)';
usr = ''
passwd = ''
topic = False
messageCount = 2000
cf = ActiveMQConnectionFactory()
connection = cf.createConnection(url, usr, passwd)
if (connection):
    print 'connection has been established'
session = connection.createSession(AcknowledgeMode.AUTO_ACKNOWLEDGE)
if (topic):
    destination = session.createTopic('TEST.PY')
else:
destination = session.createQueue('TEST.PY')
producer = session.createProducer(destination);
producer.deliveryMode = DeliveryMode.PERSISTENT
connection.start()

def sendMessages(messageCount):
    for i in xrange(messageCount):
    m = session.createTextMessage(createMessage(i))
print 'send message[%d]' % i
producer.send(m)

sendMessages(messageCount)
connection.close()